// pages/signlist/signlist.js
let md5 = require("../../utils/md5.js")
let axios = require("../../utils/util.js")
const app = getApp()
Page({
  /**
   * 页面的初始数据
   */
  data: {
    headimg: [], //上传举报照片
    nickname:'',//被举报房间名
    label: [{
        istrue: false,
        id: '1',
        name: "广告骚扰"
      },
      {
        istrue: false,
        id: '2',
        name: "淫秽色情"
      },
      {
        istrue: false,
        id: '3',
        name: "攻击谩骂"
      },
      {
        istrue: false,
        id: '4',
        name: "虚假信息"
      },
      {
        istrue: false,
        id: '5',
        name: "诈骗"
      },
      {
        istrue: false,
        id: '6',
        name: "政治敏感"
      },
      {
        istrue: false,
        id: '7',
        name: "其他"
      },
    ],
    active: 0,
    ids: [],
    idArr: [],
    chan: [],
    concent: '', //评论内容
  },
  //失去焦点时获取里面评论内容
  bindTextAreaBlur: function (e) {
    this.setData({
      concent: e.detail.value,
    })
  },
  // 选择标签
  setTab(e) {
    let label = this.data.label
    let index = e.currentTarget.dataset.index
    let id = e.currentTarget.dataset.id
    let chan = this.data.chan
    if (label[index].istrue == "1") {
      label[index].istrue = "2"
      var row = chan.map(item => item).indexOf(id)
      chan.splice(row, 1);
    } else {
      if (chan.length == 5) {
        wx.showToast({
          title: '只能选五个',
          icon: "none"
        })
        return
      }
      label[index].istrue = "1"
      chan.push(label[index].name)
      label[index].istrue = '1'
    }
    this.setData({
      label,
      chan
    })
    // console.log(this.data.chan);
  },
  chooseImg() {
    var _this = this
    wx.chooseImage({
      count: 1,
      sizeType: ['original', 'compressed'],
      sourceType: ['album', 'camera'],
      success(res) {
        var tempFilePaths = res.tempFilePaths
        // console.log(tempFilePaths)
        wx.uploadFile({
          url: axios.testInterface + '/record/uploadImg', //测试
          filePath: tempFilePaths[0],
          name: 'file',
          formData: {
            'type': '1'
          },
          success(res) {
            var data = res.data
            const strToObj = JSON.parse(data)
            // console.log(strToObj.result);
            _this.setData({
              headimg: [..._this.data.headimg, strToObj.result],
            })
          }
        })
      }
    })
  },
  // 删除图片
  close_image(e) {
    let index = e.currentTarget.dataset.index
    var arr= this.data.headimg;
    arr.splice(index,1)
    this.setData({
      headimg : arr,
    })
  },
  //提交
  addReport(){
    // return  wx.showToast({ title: '暂不开放',icon: 'none', duration: 2000})
    // let timestamp = (Date.parse(new Date()) / 1000).toString();
    let _ = this;
    let pic1;
    let pic2;
    if(_.data.headimg){
      pic1 = _.data.headimg[0]
      pic2 = _.data.headimg[1]
    }
    console.log();
    // if(!_.data.chan.length){
    // return  wx.showToast({ title: '举报选项不能为空',icon: 'none', duration: 2000})
    // }
    // if(_.data.label[6].istrue == '1'){
    //   if(_.data.concent.length == 0){
    //     return  wx.showToast({ title: '举报内容不能为空',icon: 'none', duration: 2000})
    //   }
    // }
    let content;
    content = _.data.chan.toString()+_.data.concent
    let params = {
      recordId:app.globalData.user_id,
      reportId: _.data.reportId,
      report_type:'1',
      roomId:'',
      type:'1',
      content:content, 
      pic1:pic1,
      pic2:pic2,
    };
    axios.axios({
      url: "/index/addReport",
      data: params
    }).then((res) => {
      console.log(res.data.result)
      if(res.data.status == '0'){
        wx.showToast({ title: res.data.text,icon: 'none', duration: 2000})
      }else{
        wx.showToast({
          title: res.data.text,
          icon: 'none',
          duration: 2000
        })
      }
    })
    .catch((err) => {
      this.show = false;
    });
    c
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(options);
    this.setData({
      reportId: options.reportId,
      nickname: options.nickname,
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {},

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})